﻿/******************************************************************************
    myBoard is a port of MacOS X dashboard application for windows.
    Copyright (C) 2007,2008  by Yann ALET
    Email : yann.alet@gmail.com

    myBoard is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    myBoard is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using Guide.XMLTV;
using System.ComponentModel;

namespace Guide.XMLTV
{
    public class ConfigChannel : INotifyPropertyChanged
    {
        private string _channelNumber;
        private string _channelName;
        private string _channelIconUrl;
        private string _channelOriginalString;
        private bool _selected;

        #region Properties

        public string ChannelNumber
        {
            get { return _channelNumber; }
            set { _channelNumber = value; }
        }        

        public string ChannelName
        {
            get { return _channelName; }
            set { _channelName = value; }
        }        

        public string ChannelIconUrl
        {
            get { return _channelIconUrl; }
            set { _channelIconUrl = value; }
        }        

        public string ChannelOriginalString
        {
            get { return _channelOriginalString; }
            set { _channelOriginalString = value; }
        }

        public bool Selected
        {
            get { return _selected; }
            set 
            {
                _selected = value; 
                if(PropertyChanged!=null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Selected"));
            }
        }

        #endregion

        public ConfigChannel(string channelString, GrabbersEnum grabber)
        {
            _channelOriginalString = channelString;
            
            switch (grabber)
            {
                case GrabbersEnum.tv_grab_fr:
                    {
                        string part1 = channelString.Split(';')[0];
                        _channelIconUrl = channelString.Split(';')[1];
                        _channelNumber = part1.Split(' ')[1];
                        _channelName = part1.Split(' ')[2];
                    }
                    break;

                case GrabbersEnum.tv_grab_uk_rt:
                    {
                        _channelName = channelString.Split(' ')[1];
                    }
                    break;

                case GrabbersEnum.tv_grab_ar:
                case GrabbersEnum.tv_grab_es:
                    {
                        _channelNumber = channelString.Split(' ')[1];
                        _channelName = channelString.Split(' ')[2];
                    }
                    break;

                case GrabbersEnum.tv_grab_be:
                    {
                        _channelName = channelString.Split(' ')[1];
                    }
                    break;

                case GrabbersEnum.tv_grab_ch_search:
                    {
                        _channelNumber = channelString.Split(' ')[1];
                        _channelName = channelString.Split(' ')[2].Replace("#","");
                    }
                    break;

                case GrabbersEnum.tv_grab_it:
                    {
                        _channelName = channelString.Substring(channelString.IndexOf("#") + 1);
                    }
                    break;
            }
            
        }

        public override string ToString()
        {
            return _channelOriginalString;
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
